﻿using System;
using System.Collections.Generic;
using System.Linq;
using BusinessObjects;

namespace DataLayer
{
    public partial class PatientRepository
    {
        /// <summary>
        /// Return a list of Patient objects by Last Name
        /// </summary>
        /// <returns>A List of type <see cref="Patient"/></returns>
        public List<BusinessObjects.Patient> FindPatients(int facilityID, string lastName)
        {
            List<BusinessObjects.Patient> retObject = new List<BusinessObjects.Patient>();

            using (dB = new PracticeSimpleDataContext())
            {
                var PatientList = (from x in dB.Patients where x.FacilityID == facilityID && x.LName == lastName select x).ToList();

                foreach (Patient obj in PatientList)
                {
                    retObject.Add(ConvertToBusinessObject(obj));
                }

            }
            return retObject;
        }

        /// <summary>
        /// Return a list of Patient objects by First and Last Name
        /// </summary>
        /// <returns>A List of type <see cref="Patient"/></returns>
        public List<BusinessObjects.Patient> FindPatients(int facilityID, string firstName, string lastName)
        {
            List<BusinessObjects.Patient> retObject = new List<BusinessObjects.Patient>();

            using (dB = new PracticeSimpleDataContext())
            {
                var PatientList = (from x in dB.Patients where x.FacilityID == facilityID && x.LName == lastName select x).ToList();

                foreach (Patient obj in PatientList)
                {
                    retObject.Add(ConvertToBusinessObject(obj));
                }

            }
            return retObject;
        }

        /// <summary>
        /// Return a list of Patient objects by similar text
        /// </summary>
        /// <returns>A List of type <see cref="Patient"/></returns>
        public List<BusinessObjects.Patient> FindPatientsLike(int facilityID, string searchText)
        {
            List<BusinessObjects.Patient> retObject = new List<BusinessObjects.Patient>();

            using (dB = new PracticeSimpleDataContext())
            {
                var PatientList = (from x in dB.Patients where x.FacilityID == facilityID && (x.FName.Contains(searchText) || x.LName.Contains(searchText)) select x).ToList();

                foreach (Patient obj in PatientList)
                {
                    retObject.Add(ConvertToBusinessObject(obj));
                }

            }
            return retObject;
        }


    }
}
